package com.ruoyi.web.controller.subsidy;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.subsidy.domain.bo.SysPlantingPriceBo;
import com.ruoyi.subsidy.domain.vo.SysPlantingPriceVo;
import com.ruoyi.subsidy.service.ISysPlantingPriceService;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 补贴金额
 *
 * @author nbacheng
 * @date 2025-08-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/subsidy/plantingPrice")
public class SysPlantingPriceController extends BaseController {

    private final ISysPlantingPriceService iSysPlantingPriceService;

    /**
     * 查询补贴金额列表
     */
    //@SaCheckPermission("workflow:plantingPrice:list")
    @GetMapping("/list")
    public TableDataInfo<SysPlantingPriceVo> list(SysPlantingPriceBo bo, PageQuery pageQuery) {
        return iSysPlantingPriceService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询补贴金额列表
     */
   // @SaCheckPermission("workflow:plantingPrice:list")
    @GetMapping("/listAll")
    public List<SysPlantingPriceVo> list(SysPlantingPriceBo bo) {
        return iSysPlantingPriceService.queryList(bo);
    }

    /**
     * 导出补贴金额列表
     */
  //  @SaCheckPermission("workflow:plantingPrice:export")
    @Log(title = "补贴金额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysPlantingPriceBo bo, HttpServletResponse response) {
        List<SysPlantingPriceVo> list = iSysPlantingPriceService.queryList(bo);
        ExcelUtil.exportExcel(list, "补贴金额", SysPlantingPriceVo.class, response);
    }

    /**
     * 获取补贴金额详细信息
     *
     * @param id 主键
     */
  //  @SaCheckPermission("workflow:plantingPrice:query")
    @GetMapping("/{id}")
    public R<SysPlantingPriceVo> getInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable Long id) {
        return R.ok(iSysPlantingPriceService.queryById(id));
    }

    /**
     * 新增补贴金额
     */
  //  @SaCheckPermission("workflow:plantingPrice:add")
    @Log(title = "补贴金额", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysPlantingPriceBo bo) {
        return toAjax(iSysPlantingPriceService.insertByBo(bo));
    }

    /**
     * 修改补贴金额
     */
   // @SaCheckPermission("workflow:plantingPrice:edit")
    @Log(title = "补贴金额", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysPlantingPriceBo bo) {
        return toAjax(iSysPlantingPriceService.updateByBo(bo));
    }

    /**
     * 删除补贴金额
     *
     * @param ids 主键串
     */
   // @SaCheckPermission("workflow:plantingPrice:remove")
    @Log(title = "补贴金额", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysPlantingPriceService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
